﻿using System.Collections.Generic;
using System.Linq;
using LINQtoFxCop.Core;
using Microsoft.FxCop.Sdk;

namespace LINQtoFxCop.Flaws.Design
{
  internal sealed class DesignDontInheritFromCertainTypes : FlawsIntrospectionRule
  {
    private readonly HashSet<string> _reservedBaseTypes;

    public DesignDontInheritFromCertainTypes()
      : base("DesignDontInheritFromCertainTypes")
    {
      _reservedBaseTypes = new HashSet<string> 
                            {"System.Xml.XmlDocument",
                             "AnalysisTarget.Flaws.Design.IDoItAnyways"};
    }

    protected override IEnumerable<QueryResult> Query()
    {
      return
        from type in Types
        where type.IsSubTypeOf(_reservedBaseTypes)
        select Result(type, type.BaseTypeNames());
    }
  }
}